import redis

def obtain_model_from_redis(redis_client,key):
    """
        从redis数据库中获取模型，模型以规定的xml格式字符串表示。
    """
    client = redis_client

    if not client.exists(key):
        raise Exception
    
    sim_args = client.get(key)
    return sim_args

def connect_redis(args):
    ip = args['ip']
    portid= args['port']
    dbid = 0

    return redis.StrictRedis(host=ip, port=portid, db=dbid)


if __name__ == '__main__':
    args={'ip':'localhost','port':6379,'db':0}
    redis_client = connect_redis(args)
    # 这部分可以添加测试模型
    # data = ""
    # redis_client.set('model',data)
    model = obtain_model_from_redis(redis_client)
    print(model)